package superAdmin;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

public class LoginAdmin{
    @ParameterizedTest
    @CsvFileSource(resources = "../superadminLogin.csv")
    void login(String name,String password,String loginURL,String toURL) throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        //获取登录页
        webDriver.get(loginURL);
        webDriver.manage().window().maximize();
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.DAYS);
        System.out.println("username:"+name);
        System.out.println("password:"+password);
        //输入账号密码
        webDriver.findElement(By.cssSelector("#login > div.logIn-inner > div.right-con.fr > div > div.login-form > form > div:nth-child(1) > div > div > input")).sendKeys(name);
        webDriver.findElement(By.cssSelector("#login > div.logIn-inner > div.right-con.fr > div > div.login-form > form > div:nth-child(2) > div > div > input")).sendKeys(password);
        //点击登录
        webDriver.findElement(By.cssSelector("#login > div.logIn-inner > div.right-con.fr > div > div.login-form > form > div:nth-child(3) > div > button")).click();
        webDriver.manage().window().maximize();
        sleep(3000);

        String curUrl = webDriver.getCurrentUrl();
        Assertions.assertEquals(toURL,curUrl);
        sleep(3000);

        webDriver.quit();
    }
}
